<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    {include file="common/head" /}
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form action="" id="form" class="layui-form" method="post">
            <input type="hidden" name="id" value="{$id|default=0}">
            <input type="hidden" name="model" value="{$model}">

            {foreach $info as $key=>$vo}
                {in name="key" value="brand_logo,thumb,series_thumb"}
                    {:getUploadImage($vo,$key,$title[$key])}
                {else/}
                    <div class="layui-form-item">
                        <label for="{$key}" class="layui-form-label">
                            <span class="x-red">*</span>{$title[$key]}
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" value="{$vo}" id="{$key}" name="{$key}" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-form-mid layui-word-aux">

                        </div>
                    </div>
                {/in}
            {/foreach}




            <div class="layui-form-item">
                <label for="ok" class="layui-form-label">
                </label>
                <button id="ok" class="layui-btn" lay-filter="add" lay-submit="">
                    {empty name="id"}
                    增  加
                    {else /}
                    修  改
                    {/empty}

                </button>
            </div>
        </form>
    </div>
</div>

<script>
    layui.use(['form', 'layer','laydate','layedit'],
    function() {
        $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer,
            laydate = layui.laydate;

        //自定义验证规则
        form.verify({
            zm: function(value) {
                if(!new RegExp("^[a-zA-Z0-9_\s·]+$").test(value)){
                    return '只能是字母或数字，字母和下划线开头';
                }

                if(!isNaN(value.substr(0,1))){
                    return '只能是字母或数字，字母和下划线开头';
                }
            }
        });

        laydate.render({
            elem: '#publish_time'
        });

        //监听提交
        form.on('submit(add)',
            function(data) {
                $.ajax({
                    type: "POST",
                    url: "{:url()}",
                    data: data.field,
                    success: function (result) {
                        layer.alert(result.msg, {
                            icon: 6
                        },function() {
                            xadmin.close();
                            xadmin.father_reload();
                        });
                    },
                    error: function(data) {
                        layer.alert(data.msg, {
                            icon: 2
                        },function() {
                            xadmin.close();
                        });
                    }

                });
                return false;
            });


    });


</script>

</body>

</html>
